 layui.use(['form'], function () {
        const form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var requestData = data.field
            $.ajax({
                url: 'http://localhost:8000/user/user/',
                type: 'POST',
                headers: {
                        'Authorization': localStorage.getItem('token')
                    },
                data: {
                    "username": requestData.username,
                    "gender": requestData.gender === "男" ? "M" : "F",
                    "phone": requestData.phone,
                    "email": requestData.email,
                    "occupation": requestData.occupation,
                    "Remarks": requestData.Remarks
                },
                ContentType: 'application/json',
                success: function (res) {
                    // 添加成功的逻辑
                    if (res.status === 200) {
                        // 添加成功，关闭add.html窗口
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        parent.layer.msg(res.message, {icon: 6});
                        // 刷新父页面中的表格数据
                        parent.layui.table.reload('currentTableId');
                    }
                    if (res.status === 400) {
                        layer.msg(res.message, {icon: 5});
                    } else {
                        console.log(res)
                        layer.msg(res.message, {icon: 5});
                    }
                },
                error: function (res) {
                    // 添加失败的逻辑
                    console.log(res);
                }
            })
            return false;
        });
    });